Previous | Home | Next |
<f:attribute>
Tag description: JSF <f:attribute> Tag is use to add an attribute to the UIComponent associated with the enclosing parent tag.
Example :
Step 1: Welcome page of Example
<%-- Name= welcomeJSF.jsp --%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%> <%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <%-- This file is an entry point for JavaServer Faces application. --%> <f:view> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <title>r4r.co.in</title> </head> <body> <h1><h:outputText value="Tag <f:attribute> Example"/></h1> <h:form> <h:outputLabel value="Name" /> <h:inputText value="#{attribute.name}" /> <h:commandButton id="button" action="#{attribute.submit()}"> <f:attribute name="value" value="Click To submit" /> </h:commandButton> <BR><BR> <%-- Display result --%> <h:panelGrid rendered="#{attribute.flag!= false}" > Name: <h:outputText value="#{attribute.name}" /> </h:panelGrid> </h:form> </body> </html> </f:view>
Step 2: ManagedBean class for provide logic in program
/* * Save as a attributeBean.java */ package r4r.JSF2; import javax.faces.bean.ManagedBean; import javax.faces.bean.RequestScoped; @ManagedBean(name = "attribute") @RequestScoped public class attributeBean { private String name; private boolean flag = false; /* -- Getter/Setter -- */ public boolean isFlag() { return flag; } public void setFlag(boolean flag) { this.flag = flag; } public String getName() { return name; } public void setName(String name) { this.name = name; } /* -- submit method -- */ public String submit() { flag = true; return "submit"; } }
Output :
Previous | Home | Next |